import java.util.Random;

public class Test3 {
    private static final int size = 10_000_000;
    private static final int maxValue = 100;
    private static int[] array = new int[size];
    private static long sum1 = 0;
    private static long sum2 = 0;

    public static void main(String[] args) throws InterruptedException {
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            array[i]= random.nextInt(maxValue)+1;
        }
        long startTime = System.currentTimeMillis();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < size; i+=2) {
                sum1+=array[i];
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 1; i < size; i+=2) {
                sum2+=array[i];
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long total = sum1+sum2;
        long endTime = System.currentTimeMillis();
        System.out.println("偶数和"+sum1);
        System.out.println("奇数和"+sum2);
        System.out.println(total);
        System.out.println((endTime-startTime)+"ms");
    }
}
